##################################
# R script for recoding from     #
# country name to COW country    #
# code. Based on Stata .do       #
# file made by Jana von Stein    #
# from Univ. of Michigan, and    #
# modified by Kerim Can Kavakli. #
##################################

RecodeCountries <- function(countries) {
  countries <- as.character(countries)
                        # Ensure that these are character strings.
  ccode <- vector(length = length(countries))
                        # Initialize a vector of NAs for countries codes.
  countries[countries == "Congo, Dem. Rep." | 
            countries == "Zaire" | 
            countries == "Congo, Rep." | 
            countries == "Zaire/Congo Dem Rep" | 
            countries == "D rep congo(Zaire)" |
            countries == "DR Congo (Zaire)"
            ] <- "Congo Democratic Republic of"
  countries[countries == "Cote d'Ivoire" 	| 
            countries == "Cote dIvoire" | 
            countries == "Cote D'Ivoire" | 
            countries == "Cote Divoire"
            ] <- "Ivory Coast"
  countries[countries == "Czech Republic" | 
            countries == "Czech Rep" | 
            countries == "Czech Rep (C-Slv.)" | 
            countries == "Czechoslovak"
            ] <- "Czechoslovakia"
  countries[countries == "Agypt, Arab Rep."] <- "Egypt"
  countries[countries == "Gambia, The" | 
            countries  == "Gambia The"
            ] <- "Gambia"
  countries[countries == "Germany" | 
            countries  == "FRG/Germany"
            ] <- "Germany Federal Republic of"
  countries[countries == "Iran,] Islamic Rep." | 
            countries  == "Iran Islam Rep"
            ] <- "Iran"
                        # Recoding some countries whose names change or are
                        # controversial.
  
countries[countries == "United States" |
          countries == "USA" | 
          countries == "United States of America"
          ] <- 2 

countries[countries == "Canada"] <- 20 

countries[countries == "Bahamas, The" |
          countries == "Bahamas"
          ] <- 31 

countries[countries == "Cuba"] <- 40 

countries[countries == "Haiti"] <- 41 

countries[countries == "Dominican Republic" | 
          countries == "Dom. Rep." | 
          countries == "Dominican Rep." | 
          countries == "Dominican Rep"	| 
          countries == "Dominican Rp" |
          countries == "Dominican.Rp"
          ] <- 42
		
		

countries[countries == "Jamaica"] <- 51 

countries[countries == "Trinidad and Tobago" | 
          countries == "Trinidad & Tobago" | 
          countries == "Trinidad-Tobago" | 
          countries == "Trinidad &Tobago" | 
          countries == "Trinidad Tbg" |
          countries == "Trinidad.Tbg"
          ] <- 52

countries[countries == "Barbados"] <- 53 

countries[countries == "Dominica"] <- 54 

countries[countries == "Grenada"] <- 55 

countries[countries == "St. Lucia" | 
          countries== "Saint Lucia" | 
          countries == "St Lucia"
          ] <- 56 

countries[countries == "St. Vincent] and the Grenadines" | 
          countries == "St. Vincent and Grenadines"
          ] <- 57 
countries[countries == "St.Vincent & Grenadines" | 
          countries == "St Vincent and the Grenadines" | 
          countries == "St Vincent and The Grenadines"
          ] <- 57 

countries[countries == "Antigua and Barbuda"] <- 58 
countries[countries == "Antigua"] <- 58 

countries[countries == "St. Kitts and Nevis" | 
          countries == "St Kitts and Nevis"
          ] <- 60 
countries[countries == "St. Kitts & Nevis"] <- 60 

countries[countries == "Mexico"] <- 70 

countries[countries == "Belize"] <- 80 

countries[countries == "Guatemala"] <- 90 

countries[countries == "Honduras"] <- 91 

countries[countries == "El Salvador" |
          countries == "El.Salvador"
          ] <- 92 

countries[countries == "Nicaragua"] <- 93 

countries[countries == "Costa Rica" |
          countries == "Costa.Rica"
          ] <- 94 

countries[countries == "Panama"] <- 95 

countries[countries == "Colombia"] <- 100 
countries[countries == "Columbia"] <- 100 

countries[countries == "Venezuela" | 
          countries == "Venezuala" |
          countries == "Venezuela, RB"
          ] <- 101 

countries[countries == "Guyana"] <- 110 

countries[countries == "Suriname" |
          countries == "Surinam"
          ] <- 115 

countries[countries == "Ecuador"] <- 130 

countries[countries == "Peru"] <- 135 

countries[countries == "Brazil"] <- 140 

countries[countries == "Bolivia"] <- 145 

countries[countries == "Paraguay"] <- 150 

countries[countries == "Chile"] <- 155 

countries[countries == "Argentina"] <- 160 

countries[countries == "Uruguay"] <- 165 

countries[countries == "United Kingdom" | 
          countries == "United.Kingdom" | 
          countries == "UK"
          ] <- 200 

countries[countries == "Ireland"] <- 205 

countries[countries == "Netherlands"] <- 210 

countries[countries == "Belgium" | 
          countries == "Belgium-Lux" |
          countries == "Belgium Lux" |
          countries == "Belgium.Lux"
          ] <- 211

countries[countries == "Luxembourg"] <- 212 

countries[countries == "France" | 
          countries == "France,Monac"
          ] <- 220

countries[countries == "Monaco"] <- 221 

countries[countries == "Liechtenstein"|
          countries== "Lichtenstein"
          ] <- 223 

countries[countries == "Switzerland" | 
          countries == "Switz.Liecht"
          ] <- 225

countries[countries == "Spain"] <- 230 

countries[countries == "Andorra"] <- 232 

countries[countries == "Portugal"] <- 235 

countries[countries == "Germany" |
          countries == "West Germany" |
          countries == "Germany Federal Republic of" | 
          countries == "Germany Fed Rep" |
          countries == "Germany Federal Republic" | 
          countries == "Fm German FR" |
          countries == "Fm.German.FR"
          ] <- 260 

countries[countries == "East Germany" | 
          countries == "Germany East" | 
          countries == "Fm German DR" |
          countries == "Fm.German.DR" |
          countries == "German Democratic Republic" | 
          countries == "GDR"
          ] <- 265 


countries[countries == "Poland"] <- 290 

countries[countries == "Austria"] <- 305 

countries[countries == "Hungary"] <- 310 

countries[countries == "Czech Republic" | 
          countries == "Czech Rep."
          ] <- 315
countries[countries == "Czechoslovakia"] <- 315 

countries[countries == "Slovak Republic"] <- 317 
countries[countries == "Slovakia"] <- 317 

countries[countries == "Italy"] <- 325 

countries[countries == "San Marino"] <- 331 

countries[countries == "Malta"] <- 338 

countries[countries == "Albania"] <- 339 

countries[countries == "Macedonia" | 
          countries == "Macedonia FRY"	|
	        countries == "TFYR Macedna" | 
          countries == "TFYR.Macedna" | 
	        countries== "Macedonia, FYR" | 
	        countries == "Macedonia, Former Yugoslav Republic"
	        ] <- 343

countries[countries == "Croatia"] <- 344 

countries[countries == "Yugoslavia" | 
          countries == "Fm Yugoslav" | 
          countries == "Fm.Yugoslav" |
          countries == "Serbia and Montenegro" | 
          countries == "Serbia & Montenegro *"	| 
          countries == "Serbia Montenegro" | 
          countries == "Yugoslavia, FR (Serbia/Montenegro)"	| 
          countries == "Yugoslavia, Fed. Rep." | 
          countries == "Serbia & Montenegro"	| 
          countries == "Serbia" | 
          countries == "Yugoslavia (Serbia)" | 
          countries == "Serbia and Montenegro, Former" |
          countries == "Serbia (Yugoslavia)"
          ] <- 345

countries[countries == "Bosnia and Herzegovina" | 
          countries == "Bosnia-Herz" | 
          countries == "Bosnia Hercegovenia" | 
          countries == "Bosnia-Herzegovina" | 
          countries == "Bosnia-Hercegovenia" | 
          countries == "Bosnia Herzegovina" | 
          countries == "Bosnia Herzg" | 
          countries == "Bosnia.Herzg" | 
          countries == "Bosnia & Herzegovina"
          ]  <- 346 

countries[countries == "Slovenia"] <- 349 

countries[countries == "Greece"] <- 350 

countries[countries == "Cyprus" | 
          countries == "Cyprus, Greek"
          ] <- 352

countries[countries == "Bulgaria"] <- 355 

countries[countries == "Moldova" | 
          countries == "Republic of Moldova" | 
          countries == "Moldova Rep" | 
          countries == "Rep Moldova"
          ] <- 359
		
countries[countries == "Romania" | 
          countries == "Rumania"
          ] <- 360 

countries[countries == "Russia" | 
          countries == "Russian Federation"	| 
          countries == "Russian Fed" | 
          countries == "Russian.Fed" | 
          countries== "USSR" | 
          countries == "Soviet Union" | 
          countries == "U.S.S.R." | 
          countries == "Russia (Soviet Union)" | 
          countries == "Fm USSR" |
          countries == "Fm.USSR"
          ]	<- 365

countries[countries == "Estonia"] <- 366 

countries[countries == "Latvia"] <- 367 

countries[countries == "Lithuania"] <- 368 

countries[countries == "Ukraine"] <- 369 

countries[countries == "Belarus" | 
          countries == "Belarus (Byelorussia)"
          ] <- 370

countries[countries == "Armenia"] <- 371 

countries[countries == "Georgia"] <- 372 

countries[countries == "Azerbaijan"] <- 373 

countries[countries == "Finland"] <- 375 

countries[countries == "Sweden"] <- 380 

countries[countries == "Norway"] <- 385 

countries[countries == "Denmark"] <- 390 

countries[countries == "Iceland"] <- 395 

countries[countries == "Cape Verde" | 
          countries == "C. Verde Is."
          ] <- 402

countries[countries == "Sao Tome and Principe" | 
          countries == "Saotomeetprincipe" |
          countries == "Sao Tome & Principe" | 
          countries == "Sao Tome et Principe"
          ] <- 403 

countries[countries == "Guinea-Bissau" | 
          countries == "Guinea Bissau" | 
          countries == "Guinea-Biassu" | 
          countries == "GuineaBissau"
          ] <- 404

countries[countries == "Equatorial Guinea" | 
          countries == "Eq. Guinea" | 
          countries == "Eq.Guinea"
          ] <- 411

countries[countries == "Gambia"] <- 420 
countries[countries == "The Gambia"]  <- 420 
countries[countries == "Gambia, The"]  <- 420 

countries[countries == "Mali"] <- 432 

countries[countries == "Senegal"] <- 433 

countries[countries == "Benin"] <- 434 

countries[countries == "Mauritania"] <- 435 

countries[countries == "Niger"] <- 436 

countries[countries == "Ivory Coast"] <- 437 
countries[countries == "Cote d'Ivoire" | 
          countries == "Cotedivoire" |
          countries == "Cote.Divoire" |
          countries == "Cote d`Ivoire"
          ] <- 437

countries[countries == "Guinea"] <- 438 

countries[countries == "Burkina Faso" | 
          countries == "Burkina.Faso" | 
          countries == "Burkina Faso (Upper Volta)"
          ] <- 439

countries[countries == "Liberia"] <- 450 

countries[countries == "Sierra Leone" |
          countries == "Sierra.Leone"
          ] <- 451 

countries[countries == "Ghana"] <- 452 

countries[countries == "Togo"] <- 461 

countries[countries == "Cameroon"] <- 471 

countries[countries == "Nigeria"] <- 475 

countries[countries == "Gabon"] <- 481 

countries[countries == "Central African Republic" | 
          countries == "Cent. Af. Rep." | 
          countries == "Cent. African Rep." | 
          countries == "Cen African Rep" | 
          countries == "Central African Rep" | 
          countries == "Cent.Afr.Rep"
          ] <- 482

countries[countries == "Chad"] <- 483 

countries[countries == "Congo Republic of" | 
          countries == "Congo Republic" | 
          countries == "Republic of the Congo" | 
          countries == "Congo Democratic Republic of" | 
          countries == "Congo, Republic of" | 
          countries == "Congo-Brazzaville" | 
          countries == "Congo Brazzaville" | 
          countries == "Congo (Brazzaville)" | 
          countries == "Congo Republic" | 
          countries == "Congo, Rep." | 
          countries == "Congo"
          ] <- 484

countries[countries == "Congo Democratic Republic" | 
          countries == "Congo, DR" | 
          countries == "DRCongo" | 
          countries == "D. R. Congo" | 
          countries == "Congo Democratic Republic of" | 
          countries == "Democratic Republic of the Congo" | 
          countries == "Congo, Dem. Rep."| 
          countries == "Congo, Democratic Republic Of" | 
          countries == "Congo (DRC)" | 
          countries == "Congo Kinshasa" | 
          countries == "Dem.Rp.Congo" | 
          countries == "Congo (Kinshasa)"
          ] <- 490 

countries[countries == "Uganda"] <- 500 

countries[countries == "Kenya"] <- 501 

countries[countries == "Tanzania" | 
          countries == "United Republic of Tanzania" | 
          countries == "Tanzania/Tanganyika"
          ] <- 510

countries[countries == "Burundi"] <- 516 

countries[countries == "Rwanda"] <- 517 

countries[countries == "Somalia"] <- 520 

countries[countries == "Djibouti"] <- 522 

countries[countries == "Ethiopia"] <- 530 

countries[countries == "Eritrea"] <- 531 

countries[countries == "Angola"] <- 540 

countries[countries == "Mozambique"] <- 541 

countries[countries == "Zambia"] <- 551 

countries[countries == "Zimbabwe" | 
          countries == "Zimbabwe (Rhodesia)"
          ] <- 552

countries[countries == "Malawi"] <- 553 

countries[countries == "South Africa" | 
          countries == "South.Africa" |
          countries == "S. Africa"
          ] <- 560

countries[countries == "Namibia" | 
          countries == "Nambia"
          ] <- 565

countries[countries == "Lesotho"] <- 570 

countries[countries == "Botswana"] <- 571 

countries[countries == "Swaziland"] <- 572 

countries[countries == "Madagascar" | 
          countries == "Madagascar (Malagasy)"
          ] <- 580

countries[countries == "Comoros" | 
          countries == "Comoro Is."
          ] <- 581

countries[countries == "Mauritius"] <- 590 

countries[countries == "Seychelles"] <- 591 

countries[countries == "Morocco"] <- 600 

countries[countries == "Algeria"] <- 615 

countries[countries == "Tunisia"] <- 616 

countries[countries == "Libya" | 
          countries == "Libyan Arab Jamahiriya" | 
          countries == "Libyan Arab Jamah"
          ] <- 620


countries[countries == "Sudan"] <- 625 
countries[countries == "South Sudan" | 
          countries == "Sudan, South"
          ] <- 626

countries[countries == "Iran" | 
          countries == "Iran (Islamic Republic of)" | 
          countries == "Iran, Islamic Rep." | 
          countries == "Iran (Persia)" | 
          countries == "Iran, Islamic Republic"
          ] <- 630 


countries[countries == "Turkey" | 
          countries == "Turkey/Ottoman Empire"
          ] <- 640

countries[countries == "Iraq"] <- 645 

countries[countries == "Egypt" | 
          countries == "Egypt, Arab Rep." | 
          countries == "Egypt, Arab Republic"
          ] <- 651 

countries[countries == "Syria" | 
          countries == "Syrian Arab Rep" | 
          countries == "Syrian Arab Republic" | 
          countries == "Syrian Arab Rep."
          ] <- 652 

countries[countries == "Lebanon"] <- 660 

countries[countries == "Jordan"] <- 663 

countries[countries == "Israel"] <- 666 

countries[countries == "Saudi Arabia" |
          countries == "Saudi.Arabia"
          ] <- 670 

countries[countries == "Kuwait"] <- 690 

countries[countries == "Bahrain"] <- 692 

countries[countries == "Qatar"] <- 694 

countries[countries == "United Arab] Emirates" | 
          countries == "UAE" | 
          countries == "United Arab Em." | 
          countries == "Untd Arab Em"
          ] <- 696

countries[countries == "Oman"] <- 698 

countries[countries == "Afghanistan" | 
          countries == "Afghanistan(1992-)"
          ] <- 700

countries[countries == "Turkmenistan"] <- 701 

countries[countries == "Tajikistan"] <- 702 

countries[countries == "Kyrgyz Republic" | 
          countries == "Kyrgyzstan" | 
          countries == "Kyrgystan"
          ] <- 703

countries[countries == "Uzbekistan"] <- 704 

countries[countries == "Kazakhstan"] <- 705 

countries[countries == "China" | 
          countries == "PRC" | 
          countries == "China P Rep" | 
          countries == "China (P.R.C.)"
	        ] <- 710

countries[countries == "Mongolia"] <- 712 

countries[countries == "Taiwan" | 
          countries == "Taiwan (China)" | 
          countries == "China (Taiwan)"
          ] <- 713

countries[countries == "Korea,] Dem. Rep." | 
          countries == "PRK" | 
          countries == "Korea, DPR" | 
          countries == "Korea, Democratic Republic" | 
          countries == "Korea Democratic Republic" | 
          countries == "Korea North" | 
          countries == "Korea, North" | 
          countries == "North Korea" | 
          countries == "Koreademprep" | 
          countries == "Korea, People's Republic of" | 
          countries == "Korea Dem P Rep" | 
          countries == "Korea D P Rp" |
          countries == "Korea.D.P.Rp"
          ] <- 731

countries[countries == "Korea Republic of" | 
          countries == "ROK" | 
          countries == "South Korea" | 
          countries== "Korea, Republic of" | 
          countries == "Republic of Korea" | 
          countries == "Korea Rep" 	| 
          countries== "Korea, Rep." | 
          countries== "Korea, South" | 
          countries == "Korea South" | 
          countries == "Korea Rep." |
          countries == "Korea.Rep."
          ] <- 732

countries[countries == "Japan"] <- 740 

countries[countries == "India"] <- 750 

countries[countries == "Bhutan"] <- 760 

countries[countries == "Pakistan"] <- 770 

countries[countries == "Bangladesh"] <- 771 

countries[countries == "Myanmar" |
          countries == "Burma" | 
          countries == "Myanmar" | 
          countries == "Burma (Myanmar)" |
          countries == "Myanmar (Burma)"
          ] <- 775

countries[countries == "Yemen People's] Republic" | 
          countries == "Yemen, Republic of" | 
          countries == "Yemen Republic" | 
          countries == "Yemen" | 
          countries == "Yemen, People's Republic of" | 
          countries == "Yemen, Rep." | 
          countries == "Yemen, Republic of " |
          countries == "Yemen Republic" | 
          countries == "South Yemen"
          ] <- 679

countries[countries == "Yemen (AR)" | 
          countries == "Yemen Arab Republic" |
	        countries == "North Yemen" | 
	        countries == "Yemen, North"	|
	        countries == "Fm Yemen AR" |
          countries == "North Yemen"
	        ] <- 678
	
countries[countries == "Yemen (PDR)" | 
          countries == "Yemen People's Republic" | 
	        countries == "Yemen (Arab Republic of Yemen)" | 
	        countries == "Fm Yemen Dm" |
          countries == "Fm.Yemen.Dm"
	        ] <- 680

countries[countries == "Sri Lanka" | 
          countries == "Sri.Lanka" |
          countries == "Sri Lanka (Ceylon)"
          ] <- 780

countries[countries == "Maldives"] <- 781 

countries[countries == "Nepal"] <- 790 

countries[countries == "Thailand"] <- 800 

countries[countries == "Cambodia" | 
          countries == "Cambodia (Kampuchea)"
          ] <- 811

countries[countries == "Laos" | 
          countries == "Lao People's Democratic Republic" | 
          countries == "Lao P Dem Rep" | 
          countries == "Lao PDR" | 
          countries == "Lao P.Dem.R" |
          countries == "Lao.P.Dem.R"
          ] <- 812

countries[countries == "Vietnam" | 
          countries == "North Vietnam" | 
          countries == "Vietnam, North" | 
          countries == "Viet Nam" | 
          countries == "Viet.Nam" | 
          countries == "Vietnam, Democratic Republic of"
          ] <- 816

countries[countries == "Republic of Vietnam" | 
          countries == "South Vietnam" | 
          countries == "Vietnam, South"
          ] <- 817 

countries[countries == "Malaysia"] <- 820 

countries[countries == "Singapore"] <- 830 

countries[countries == "Brunei"|
          countries== "Brunei Darussalam"
          ] <- 835 

countries[countries == "Philippines"] <- 840 

countries[countries == "Indonesia"] <- 850 

countries[countries == "Timor-Leste" | 
          countries == "Timor Leste" | 
          countries == "East Timor"
          ] <- 860 

countries[countries == "Australia"] <- 900 

countries[countries == "Papua New Guinea" | 
          countries == "P. N. Guinea"	| 
          countries == "Papua N.Guin"
          ] <- 910

countries[countries == "New Zealand" |
          countries == "New.Zealand"
          ] <- 920 

countries[countries == "Vanuatu"] <- 935 

countries[countries == "Solomon Islands" | 
          countries == "Solomon Is." | 
          countries == "Solomon Is" 
          ] <- 940

countries[countries == "Kiribati"] <- 946 

countries[countries == "Fiji"] <- 950 

countries[countries == "Tonga"] <- 955 

countries[countries == "Marshall Islands"] <- 983 

countries[countries == "Palau"] <- 986  

countries[countries == "Micronesia,] Fed. Sts." | 
          countries== "Micronesia" | 
          countries == "Federated States of Micronesia" | 
          countries == "Micronesia (Federated States of)"
          ] <- 987

countries[countries == "Samoa"] <- 990 
return(as.numeric(countries))
                        # Those observations that are not included in
                        # this list will become NAs.
}

